Hello,
So far I have studied HTML-CSS-PHP and SQL. I got a very good understanding of all of them and now I am trying to create my first web app. What I can't figure out is what do I need in order to be able to connect to my SQL database?
I followed these tutorials: https://www.w3schools.com/php/php_mysql_connect.asp
First I got an error that class MySQLi is missing. Then I changed the name of the file php.ini-development to php.ini and I got rid of that message. (I found this fix on google).
I use php 7 version.
But now nothing happens. I get no message regarding if the connection to the database is successful or not. What am I missing?
So far I have installed: PHP 7 with server started from cmd, ATOM for text editing, MySQL server and MySQL Workbench for user interface.
I already created my forms, my databse, my tables, etc...
Can you please give me some guidance?
Thank you.
PHP-SQL
Moderators: egami, macek, gesf
mysql_connect is deprecated in PHP MySQLi was intended to help people transition from MySQL and use prepared statements for improved security. The SQL should stay much the same.
I know it's confusing, but basically you should look to learn PDO, I don't know if that web site teaches it, but they shouldn't teach MySQLi anymore.
I know it's confusing, but basically you should look to learn PDO, I don't know if that web site teaches it, but they shouldn't teach MySQLi anymore.
Ok, I change my code to PDO:
I get this error now: Connection failed: could not find driver
I can't understand why it has to be so complicated to connect to a database. It should be a very easy process.... What shoul I do?
Code: Select all
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
I can't understand why it has to be so complicated to connect to a database. It should be a very easy process.... What shoul I do?
I uploaded this code to my website and I created a database there. Finally I got connected successfully using PDO and it worked very straight forward. Wich I think is normal..
I was thinking, wouldn't it be better to work directly on the server? Seems to me I don't need to have locally installed neither: mysql, php, apache or anything else.
All I need is an editor like Atom that supports ftp project folder?
Do you know anything like this? Preferably free?
Nowadays internet connections are very good so I think you could work directly on the server. What do you think?
PS.
I tried to get into apache but things got crazy complicated. Also, there are a lot of settings in the php.ini files and many tricks that you couldn't possibly think of. I don't think it's ok not to be able to make a connection without searching the internet for a week. Things should be much more easier.
I was thinking, wouldn't it be better to work directly on the server? Seems to me I don't need to have locally installed neither: mysql, php, apache or anything else.
All I need is an editor like Atom that supports ftp project folder?
Do you know anything like this? Preferably free?
Nowadays internet connections are very good so I think you could work directly on the server. What do you think?
PS.
I tried to get into apache but things got crazy complicated. Also, there are a lot of settings in the php.ini files and many tricks that you couldn't possibly think of. I don't think it's ok not to be able to make a connection without searching the internet for a week. Things should be much more easier.