Created
September 13, 2012 10:52
-
-
Save CodeNegar/3713548 to your computer and use it in GitHub Desktop.
PHP: connect to mysql database utf-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = "SELECT * FROM table1"; | |
$my_connection = mysql_connect ( "localhost" , "user_name" , "pass" ); | |
if (!$my_connection) | |
{ | |
die( 'Could not connect to database : ' . mysql_error()) ; | |
} | |
mysql_set_charset('utf8'); | |
$db_selected = mysql_select_db('database_name', $my_connection); | |
if (!$db_selected) { | |
die (mysql_error()); | |
} | |
$result = mysql_query($query, $my_connection); | |
if (!$result) { | |
die("error: " . mysql_error()); | |
} | |
$rows = array(); | |
while ($row = mysql_fetch_assoc($result)) { | |
$rows[] = $row; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment