Now do the project needs PHP connection MySQL database, although learned before, but now basically forget, and then find the relevant data to solve the problem, the following small series of specific methods to share in the script home platform for everyone to learn
The specific code looks like this:
<?php//sets the character set header (' content-type:text/html; Charset=utf8 ');//Connection Database $link = mysql_connect ("localhost", "root", " 123456 "), if (! $link) {echo ' Database connection failed ...<br> '; exit (-1);} Else{echo "Database connection succeeded ...<br>";} Select a database as the default database mysql_select_db (' PHP_SJK ');//Execute SQL INSERT statement $sql = "INSERT INTO zh VALUES (NULL, ' Wang Jie ', ' 123456 ')"; $CR = Mysql_ Query ($sql);//Determine if Insert succeeded if (! $cr) {echo "Data insertion failed. <br> ";} Else{echo "Data insertion succeeded. <br> ";} Execute SQL query Statement $sql = "SELECT * from zh"; $CR = mysql_query ($sql);//Get the returned result set and loop output echo "data show:<br><br><br> "while ($a = mysql_fetch_row ($CR)) {echo" {$a [0]}--{$a [1]}--{$a [2]}<br> ";} Close database connection mysql_close ($link);? >
About PHP connection MySQL database code to introduce you so much, welcome to the collection, thank you!