PHP connection MySQL database, phpmysql database
Because the first two days a project needs PHP to connect to MySQL, although previously learned, but now basically forgot all about it, but later found a lot of information to find the method:
Php//Set character sets Header(' content-type:text/html; Charset=utf8 '); //connecting to a database $link=mysql_connect("localhost", "root", "123456"); if(!$link){ Echo' Database connection failed ...
'; Exit(-1); }Else{ Echo"Database connection succeeded ...
"; } //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.
"; }Else{ Echo"Data insertion succeeded.
"; } //Execute SQL query statement $sql= "SELECT * from en"; $CR=mysql_query($sql); //gets the returned result set, and loops the output Echo"Data show:
"; while($a=Mysql_fetch_row($CR)){ Echo"{$a[0]} ——{$a[1]} ——{$a[2]}
"; } //To close a database connection Mysql_close($link);?>
http://www.bkjia.com/PHPjc/1093868.html www.bkjia.com true http://www.bkjia.com/PHPjc/1093868.html techarticle PHP connection MySQL database, Phpmysql database because the first two days a project needs PHP connection MySQL, although previously learned, but now basic also forget, but later find a lot of capital ...