Open huirongcs opened 4 years ago
@huirongcs oh finally, connecting DB (゚∀゚)
What is the last level of these lesson?
Hmm, this is just for PHP course. There are other courses inside this account. After this probably I will continue learning "Complete SQL Database Training Course" or "JSON AJAX Data Transfer To MySQL Database Using PHP"? 🤔
ok~
@huirongcs After that, I recommend you to create a side project with MVC architecture. It could be good if there are some MVC architecture courses.
String Functions (Cont'd)
Explode 💥 & Implode
Explode: Split a string by a string, and returns an array of strings.
Example: Split a sentence by detecting a comma
↑ prints out ↓
Note: Notice that the commas are also gone.
If we split the sentence by spaces, it’d be:
↑ prints out ↓
Implode: Join array elements with a string; returns a string
Continuing from example above…
↑ prints out ↓
If we add HTML in between, it works too.
↑ prints out ↓
Setting up connection to database
1) Create a file core/settings.php which contains the host, user, password, and database name:
2) Create a file core/conn.php which will connect the server and database together, using the settings.php file we created.
If $link has error, the codes will stop there and print out error
mysqli_connect_error()
in when we preview index.php3) Create a file index.php which contains this:
For the above, it will print out ↓
There’s an error since this database has not been created.
4) Creating database with sql query. Create a new file setup.php (this only needs to be run 1 time)
In this case, the [connection object] is
$link
, from the file core/conn.php5) Go to http://localhost/my_project_folder/setup.php on the browser to run this page, and the database elearning will be automatically created.