How to check for the correctness in form of the configuration data is the database name and password?

Make possible to install user script on the server. In the form enter connection information to the database and the form is sent to the processor to record the data (the database password, username and database name) in config file. Well if introduced correctly. If not true - how to check and return the user back to enter correct data?
July 8th 19 at 12:13
2 answers
July 8th 19 at 12:15
Solution
Are you serious?

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
 die('connection Error:' . mysql_error());
}
echo 'connected Successfully';
mysql_close($link);


php.net/manual/ru/function.mysql-connect.php

try {
 $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
 foreach($dbh->query('SELECT * from FOO') as $row) {
print_r($row);
}
 $dbh = null;
} catch (PDOException $e) {
 print "Error!: ". $e->getMessage() . "<br>";
die();
}


php.net/manual/ru/pdo.connections.php
Are you serious? mysql_connect??? - lily.Kozey commented on July 8th 19 at 12:18
don't know how to use it, I sent the form data to the handler, the handler did the data entry in the config file, that I would not think ( - Liliana_Hickle82 commented on July 8th 19 at 12:21
AAA came, thank you ) - Liliana_Hickle82 commented on July 8th 19 at 12:24
in the question did not indicate how the author connects, so I gave an example with mysql_connect - nicklaus.Will commented on July 8th 19 at 12:27
inappropriate, unbecoming and unprofessional to advise a person outdated in all senses method, which also do not have even to muskulu must be connected. Most certainly resent the fact that mysql_ driver deprecated since 2011. In new versions do not support it by default. - lily.Kozey commented on July 8th 19 at 12:30
: people have asked about how to test the DB connection, the example shows how to do it and what to use author to work with mysql, that's his business. - nicklaus.Will commented on July 8th 19 at 12:33
July 8th 19 at 12:17
Solution
The database can (and should) return the token for the connection or an error. Respectively look normal database adapter in the manual, what and how to connect, create a connection instance with the settings you have, if all goes well, "continuing the conversation" (with). If it throws an error - intercept, send the user back to step fill in the fields, and write what the error was.
Profit.
It's a good step in development, believe me, reading about the methods of database connection you're already a little closer to the Pro status, you're headed for this? mysql_connect possible, but unnecessary if you read the manual, the page will be written in large letters deprecated, do not be lazy to find out what this overseas term ). - lily.Kozey commented on July 8th 19 at 12:20
thank you - Liliana_Hickle82 commented on July 8th 19 at 12:23

Find more questions by tags PHP