Jump to content

Not connecting to MySql database using $CONN in attempting to set up ElementorPro CRUD


Go to solution Solved by mac_gyver,

Recommended Posts

Hi.  It is great to find php support and I thank you in advance and even for taking the time to help me.

I have been watching numerous CRUD tutorials and videos and want to duplicate that setup. Actually,I want to increase the usual 2-3 column sample demos to maybe another dozen or so columns.

The problem seems to be I can never connect successfully and I strongly suspect it is due to a pathing error or directory level when placing my php connection code.

All of the online guru tutorials seem to be developed on that tutor's own localhost.   I am not working on a local host of my own on my development computer.

 

Instead I use a shared server at a hosting company.  Their path is different than the tutorial developer.  I don't seem to be getting this right and have failed everytime.  Using phpMyAdmin is the only way I can work with the database.  No problems. But, with every senario I try, using the Elementor Pro Form, the form data is never inserted into the MySQL

 

" bruce_ " preceeds my database name and table in the c-panel and the host has told me it must be included as a part of my php argument to define the path for connection.

Are there some special rules for connecting to a shared server vs. developing on a your own localhost that I need to follow?

 

Thx 

BAV

 

 

<?php

$conn = new mysqli("localhost", "tony", "thisismypassword", "php_demo");

?>

 

 

  • Solution

you should be learning, developing, and debugging your code/queries on a localhost development system. trying to use public/online hosting is a waste of time, constantly uploading, and making sure there were no upload errors, to see the result of each change. until your code is secure, this opens the possibility of your web hosting getting abused by hackers. also, most cheap shared web hosts disable things like php's error related settings and database error settings that you need in order to get php and your database statements to help you. they also set disk and web server caching so that you won't immediately see the result of changes you make to your code.

the database hostname on shared hosting is generally not going to be localhost. your web host should have an FAQ section that gives examples of connection credentials. the control panel where you created your database user/password should also list the hostname/ip address to use and any prefix for the username.

if you can setup php's error related settings, you need to set error_reporting to E_ALL and set display_errors to ON. these should be in the php.ini on your system so that they can be changed at a single point.

next, you always need error handling for statements that can fail. for database statements that can fail - connection, query, prepare, and execute, the simplest way of adding error handling, without adding logic at each statements, is to use exceptions for errors and in most cases simply let php catch and handle the exception, where php will use its error related settings (see the above paragraph) to control what happens with the actual error information (database statement errors will 'automatically' get displayed/logged the same as php errors.) to set the error mode to exceptions for the mysqli extension, add the following line of code before the point where you make the database connection -

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

lastly, if you are just starting with php/MySql, learn and use the simpler and more modern PDO database extension.

Edited by mac_gyver
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.