Copy link to clipboard
Copied
DW created PhP (v7.4) page is throwing this warning linked to my DB connection file.
Seen a few suggestions recommending adding the following to the php.ini file
Under dynamic extenstions;
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
But it hasnt resolved the warning issue.
Any other suggestions ?
Copy link to clipboard
Copied
What do your error logs tell you?
See this:
https://www.linode.com/community/questions/19631/internal-server-error-strpos-empty-needle
Copy link to clipboard
Copied
what is your connexion piece of code ?
Copy link to clipboard
Copied
I use WebAssists extention to create my local and remote connection:
The warning cites line 15 - ive highlighted it below.
<?php
# FileName="WADYN_MYSQLI_CONN.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_MyDevDB = "localhost";
$database_MyDevDB = "mydevices";
$username_MyDevDB = "devuser";
$password_MyDevDB = "pE8/AOzpL(";
@Session_start();
$foundConnection = false;
if ($foundConnection == false) {
$domains = explode(",","192.168.0.143");
for ($domindex = 0; $domindex<sizeof($domains) && !$foundConnection; $domindex++) {
$domainCheck = trim($domains[$domindex]);
if (strpos(strtolower($_SERVER["SERVER_NAME"]),strtolower($domainCheck)) !== false && ($domainCheck == "" || strpos(strtolower($_SERVER["SERVER_NAME"]),strtolower($domainCheck)) == strlen($_SERVER["SERVER_NAME"])-strlen($domainCheck))) {
$hostname_MyDevDB = "192.168.0.143";
$database_MyDevDB = "mydevices";
$username_MyDevDB = "devuser";
$password_MyDevDB = "pE8/AOzpL(";
$foundConnection = true;
}
}
}
$MyDevDB = mysqli_init();
if (defined("MYSQLI_OPT_INT_AND_FLOAT_NATIVE")) $MyDevDB->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, TRUE);
$MyDevDB->real_connect($hostname_MyDevDB, $username_MyDevDB, $password_MyDevDB, $database_MyDevDB) or die("Connect Error: " . mysqli_connect_error());
?>
Copy link to clipboard
Copied
$domains = explode(",","192.168.0.143");
I think should read
$domains = explode(",","[URL of your site]");
If that does not work, ask Ray at WebAssist.
Copy link to clipboard
Copied
I'm scratching my head, why would you need all that heap of bilge just to connect to your database........the mind boggles.
Copy link to clipboard
Copied
For those wishing to avoid fiddling with two or more connection scripts for say test and live scenarios.
Copy link to clipboard
Copied
Humm..... l usually use the same connection info for local and remote.....l guess my remote server is flexible and allows to do that where some may not.
Copy link to clipboard
Copied
Realistically this is probably all the code you would need. Test to see if its YOUR localhost server, if not use the remote connection:
$url = 'http://localhost/';
if(strpos($url, 'localhost') == true) {
$connect = mysqli_connect("serverName1", "user1", "pass1", "dbName1");
}
else {
$connect = mysqli_connect("serverName2", "user2", "pass2", "dbName2");
}
I've not tested it but it seems like it would work.
Copy link to clipboard
Copied
For those wishing to avoid fiddling with two or more connection scripts for say test and live scenarios.
By @paulc89302236
Personally, for each projects, I generally work with several servers, for different purpose (tests, research team, customer proposal, beta version, production...) and depending on the projects and the teams, the problem rarely comes from the connection scripts, but from the (fine) configuration, and uses, of the servers themselves...
in this sense, I have taken for habit, maybe wrongly, to set up a series of files that manage connections, rebalancing settings, constant dispatching, etc... that I place in a cloaked way, on my local space.
I name them in a very HARD way, for example __connect-server-foo.php or __SESSION_settings_server-foo.php... and so on.
In fact, these files are placed, modified, adapted only very rarely on their respective servers, where of course, they are named in a polymorphic way such as __connect.php or __SESSION_settings.php,
Then, in order to be invoked only in a unique way in the form of rectification due to the access path so different according to the servers :
<?php
include_once('/'.trim( $_SERVER['DOCUMENT_ROOT'], '/' ).'/fooshared/__connect.php');
?>