+ 2

Am developing a chatbox its almost done but i need a php connection code. Any help is appreciated, am using HTML and Javascript

9th Oct 2017, 3:38 PM
Edward Mwangi
Edward Mwangi - avatar
8 Answers
+ 2
So your after a simple database connection right? I would suggest looking at PDO for best practices but if that seems a little confusing you could always use the below and include it on the same page as your SQL statements. <?php $host="XXX"; $username="XXX"; $password="XXX"; $db_name="XXX"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); ?>
9th Oct 2017, 3:41 PM
ihateonions
+ 1
So are you using MYSQL to store the messages or are you storing it locally using javascript?
9th Oct 2017, 3:49 PM
ihateonions
+ 1
mysql
9th Oct 2017, 3:50 PM
Edward Mwangi
Edward Mwangi - avatar
+ 1
Hi, I think mysql got depreciated. Give the syntax for the mysqli or MariaDB
9th Oct 2017, 3:52 PM
Ifeoluwa D. Ojo
Ifeoluwa D. Ojo - avatar
+ 1
Your correct, mysql is depreciated and i would always advise using PDO with mysqli instead. Just couldn't be bothered to write one out lol. @Edward, i will write a simple easy to understand snippet of code for you later this evening, just getting a tad busy at work.
9th Oct 2017, 4:08 PM
ihateonions
0
Ok thanks.
9th Oct 2017, 4:09 PM
Ifeoluwa D. Ojo
Ifeoluwa D. Ojo - avatar
0
Hmm, I have an Backend API for MVC written on PHP, but I don't know if it'll work for you as it worked for me.
9th Oct 2017, 5:18 PM
Freezemage
Freezemage - avatar
- 1
my question is how to get messages displayed after i load to the website
9th Oct 2017, 3:43 PM
Edward Mwangi
Edward Mwangi - avatar