Created
November 20, 2016 13:55
-
-
Save ildarkhasanshin/ae2df184025bd656d9b453ceabb81286 to your computer and use it in GitHub Desktop.
mysql quick connect
This file contains 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 | |
$db_host = 'localhost'; | |
$db_user = ''; | |
$db_pass = ''; | |
$db_name = ''; | |
$db_table = ''; | |
$db_field = ''; | |
$link = mysql_connect($db_host, $db_user, $db_pass); | |
if (!$link) { | |
die(mysql_error()); | |
} else { | |
mysql_select_db($db_name, $link) or die(mysql_error()); | |
mysql_query("SET NAMES 'cp1251'"); | |
mysql_query("SET CHARACTER SET 'cp1251'"); | |
} | |
$query = ' | |
select * from db_table | |
'; | |
$result = mysql_query($query); | |
if (!$result) { | |
die(mysql_error()); | |
} | |
$count = mysql_num_rows($result); | |
if ($count > 0) { | |
while ($row = mysql_fetch_assoc($result)) { | |
echo $row[$db_field]; | |
} | |
} | |
mysql_free_result($result); | |
mysql_close($link); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment