Created
May 31, 2019 02:26
-
-
Save BAHC/8dbe66ac0c86221c9d76e9efd0724090 to your computer and use it in GitHub Desktop.
MySQL Improved
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_user = 'root'; | |
$db_pass = 'toor'; | |
$db_host = 'localhost'; | |
$db_port = 3306; | |
$db_name = 'my_db'; | |
$db_encoding = 'utf8'; | |
//mysqli_connect(host, username, password, dbname, port, socket); | |
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name, $db_port); | |
// Check connection | |
if (mysqli_connect_errno()) | |
{ | |
echo "Failed to connect to MySQL: " . mysqli_connect_error(); | |
} | |
// Change character set to utf8 | |
mysqli_set_charset($conn, $db_encoding); | |
mysqli_select_db($conn, 'my_data'); | |
$sql = 'SELECT * FROM my_table WHERE 1 LIMIT 1000'; | |
$result = mysqli_query($conn, $sql); | |
// Fetch all | |
$my_data = mysqli_fetch_all($result, MYSQLI_ASSOC); | |
// Free result set | |
mysqli_free_result($result); | |
mysqli_close($conn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment