PHP simple read for MySQL instance, phpmysql instance
Read MySQL Database
Cases.
Code to copy code as follows
$link =mysql_connect ("localhost", "root", "previous Administrator password");
if (! $link) echo "Not connected successfully!";
mysql_select_db ("Infosystem", $link); Select Database
$q = "SELECT * from Info"; SQL query Statements
mysql_query ("SET NAMES GB2312");
$rs = mysql_query ($q); Get Data Set
if (! $rs) {die ("Valid result!");}
echo "
"; echo "
Department Name |
Employee Name |
PC Name |
"; while ($row = Mysql_fetch_array ($rs)) echo "
$row [1] |
$row [2] |
$row [3] |
"; Show Data echo "
";
Mysql_free_result ($RS); To close a data set
?>
Chinese display garbled problem
When we access the MySQL database by PHP in the original way, even if the default character set of the table is UTF8 and the query is sent through UTF-8 encoding, you will find that the database is still garbled.
In fact Jane (www.111cn.net) Single method is set by phpMyAdmin.
Set the following:
1: Language set to Chinese (zh-utf-8)
2:mysql Character Set: UTF-8 Unicode (UTF8)
3:mysql Connection Proofing: Utf8_general_ci
4: When adding database and data table, organize item selection utf8_general_ci
Through the above settings, in the phpMyAdmin operation and query, the Chinese characters are not garbled.
But you will find that in the PHP program with the previous SQL statement query results or garbled, the problem is on the connection connection layer.
The workaround is to send a query statement after the database is successfully connected:
Code to copy code as follows
1: $this->linkid = mysql_connect ($this->host, $this->user, $this->password);
2:mysql_query (' SET NAMES ' UTF8 ', $this->linkid);
Or:
DEFINE (' LINK ', mysql_connect (Db_host, Db_user, Db_password));
mysql_query ("SET NAMES ' UTF8 '", LINK);
GBK-encoded
Code to copy code as follows
$mysql _mylink = mysql_connect ($mysql _host, $mysql _user, $mysql _pass);
mysql_query ("SET NAMES ' GBK '");
From:http://www.111cn.net/phper/php-database/57069.htm
A simple PHP Insert database/Read sample
Untitled Document </title>
if (Isset ($_post[' TJ '))//If you click Submit
{
$conn =mysql_connect ("localhost", "username", "password");
mysql_select_db ("Eastses", $conn);
mysql_query ("Set names UTF8", $conn);
Date_default_timezone_set ("asia/chongqing");
$sql = "INSERT into ' eastses '. ' Classmate ' (' id ', ' name ', ' nickname ', ' Birthday ', ' home ', ' blood ', ' qq ', ' Weibo ', ' email ', ' Phone ', ' hobby ', ' food ', ' sentence ', ' gift ', ' lover ', ' keenon ', ' unforgettable ', ' wanttobecome ', ' ideal ', ' other ') VALUE S (' ". $_post[' id ')." ', ' ". $_post[' name ']." ', ' ". $_post[' nickname ']." ', ' ". $_post[' birthday ']." ', ' ". $_post[' home '." , ' ". $_post[' blood ']." ', ' ". $_post[' QQ '] ... Remaining full text >>
PHP Write Database example
If your database is set up it's easy, use PHP to connect your database!
$link = mysql_connect (' localhost ', ' user ', ' pwd ');//Your database user name and password
mysql_query (' Set names UTF8 '); Set character sets
mysql_select_db (' db ');//Select your database
$sql = "Here is your SQL statement";
mysql_query ($sql);//Send SQL statement
Mysql_close ();//close connection
http://www.bkjia.com/PHPjc/886000.html www.bkjia.com true http://www.bkjia.com/PHPjc/886000.html techarticle PHP Simple Read example of MySQL, phpmysql instance read MySQL database example. Code to copy the code below? PHP $link =mysql_connect ("localhost", "root", "previous Administrator password"); if ( .....