Establish Database connection
-
I am trying to insert form submissions into my custom table in my wordpress site. But I am not able to establish connection to database.In my functions.php –
$servername = "localhost"; $username = "xyz"; $password = "xyz"; $dbname = "xyz"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if (!$con) { return new WP_Error("database_error",__("No Connection: ". $conn->connect_error,'feasible_check')); }
Below is link to page with form, on filling this and submit, insert action to DB is performed.
FormI will get ‘No Connection:’ response.I have verified username/password/dbname is intact. I donot want to use any plugins.
I have also tried using
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
instead of mysqli, even with that approach i am not able to connect.I have tried using wpdb , but since this is custom table it is not listed in
$wpdb->tables
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Establish Database connection’ is closed to new replies.