Prev charpter-> 1.Php
back to index
2 Get Start MySql
2.1 install MySql
- Option 1: (Recommend for beginner) Download and install
XAMPP
the popular PHP-MySql development environment
- Option 2: Download Mysql community version
- Option 3: MariaDB is MySql open source fork
2.2 install MySql Admin UI
-
- If you installed with
XAMPP
, it come with a MySql admin UI phpMyAdmin
-
- or you could install another my sql UI you like ex.
2.3 Connect MySql DB from PHP
-
- you need a MySql driver for PHP to use MySql DB
- XAMPP already include the MySQLi, you could just use it
- For non XAMPP user you need manually install php mysql connection
-
- MySql default root username is
root
-
- Try below code to check sql connection
<?php
$server_name = "localhost"; //where is your mysql server server
$username = "root"; // the MySql username
$password = ""; // the Mysql password
// Create a mysqli connection
$conn = new mysqli($server_name, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}else{
echo "Connected successfully";
}
?>
-
- Enable mysqli extension
- if you got error like ‘Fatal error: Uncaught Error: Class “mysqli” not found in’, please go to
C:\php
, update php.ini or rename php.ini-development to php.ini, remove ‘;’ in front of extension=mysqli
to enable it like below
php.ini
extension=mysqli
;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
;extension=oci8_19 ; Use with Oracle Database 19 Instant Client
;extension=odbc
;extension=openssl
;extension=pdo_firebird
2.4 php mysql examples
- Check mySql connection code sample: mySqlConnect
- Create a separate db connection files dbConfig.php file for test.php page to use.
- Use Php to create a new table to
Test
database createNewTable_test.php
- A From to insert new rows to database table insertRow_test.php
- Test page to load table row from database getData_test.php
- Html and Table example GetStudents
2.5 MySql Query example
- Create a Table
Prev chapter-> 1.Php
back to index