Skip to content

Instantly share code, notes, and snippets.

@CodeNegar
Created September 13, 2012 10:52
Show Gist options
  • Save CodeNegar/3713548 to your computer and use it in GitHub Desktop.
Save CodeNegar/3713548 to your computer and use it in GitHub Desktop.
PHP: connect to mysql database utf-8
<?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