NA//Off Beat Question For GEEKS\\

FlySince9

En-Route
Joined
Mar 7, 2011
Messages
3,151
Location
Huntersville, NC
Display Name

Display name:
Jerry
Anybody out there fluent in PHP and mysql that I can private message and ask a few questions???
 
I'm pretty good in SQL...I've worked with mySQL, but done more in MS SQL than MySQL.
 
I have to read other's stuff regularly and can throw a rock and hit 15 or so experts on both.

Don't really need to PM it, though. Might as well ask it in public.
 
I maintain another vBulletin site, so it's pretty much all PHP and MySQL.
Ask awa
 
I maintain another vBulletin site, so it's pretty much all PHP and MySQL.
Ask away, someone will have the answer.
 
I'm at work right now... I will post the code snippet that's been causing me headaches this evening... I appreciate the responses... thanks!
 
Definitely post it here. One of us will be able to spot the issue(s). Also post the error/line you are receiving it on if possible.
 
<!DOCTYPE html>

<?php
$servername = "localhost";
$username = "i use a username here";
$password = "i have a password here";
// Create connection
$conn = mysqli_connect($servername, $username, $password);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";

mysqli_select_db ("members");

SELECT * From main;

?>


The table I am trying to select records from is main from the members database.
I am using xampp local host and my files are in the htdocs directory and this file is in a
subdirectory called memberpage. This should
be a simple thing but I keep getting....

Parse error: syntax error, unexpected 'main' (T_STRING) in C:\xampp\htdocs\memberpage\dbtest.php on line 19
 
I'm assuming that the connect is successful?

What's the first value that should be returned?

Rich
 
Last edited:
I'm assuming that the connect is successful?

What's the first result that would be returned?

Rich

I just have a simple test table with fields First, Last, Rank, and Date_Joined

The Select * From ... Should Select all those fields with two test records...

While waiting for a response from POA I was able to get further...

I added these two lines :

mysql_select_db ("members,$conn");

mysql_query ("SELECT * From /main");

which resolved the Parsing error... Now I'm working on getting the thing to output the query... Man... I used to do this, with my eyes closed, 5 years ago... haven't done any coding since then and now I'm no better than a novice... Getting old really sucks!
 
I'm not a big fan of " SELECT * " myself. But that's neither here nor there.

I think what you need next is something like:

PHP:
$query="SELECT * FROM /main";
$result=mysql_query($query);

$first0 = mysql_result($result,0,"FirstName");
$last0 = mysql_result($result,0,"LastName");
etc.

(using the correct labels, of course).

Rich
 
Last edited:
It's been too long since I've done php... but you may wish to consider a really good IDE to help you out. I really like JetBrains' products. Here's a PHP one they have: http://www.jetbrains.com/phpstorm/ . I use their java and python product.

I'm sure there's a free offering out there as well.

One thing I will say is this: never use a wildcard (*) in a SQL query. Always explicitly list the columns that you want to retrieve, and try to do as much processing & filtering on the server (i.e., in the query) as you can. Broad strokes... there are exceptions. The idea here being that you can more easily track schema and code changes when you explicitly list things.

Next, run every query you write through the query planner and make sure you're not asking questions the database doesn't know how to run well.

Finally - consider separating all of your DB common code out into includes.

And try to avoid using PHP.... or MySQL... :)
 
I'm not a big fan of " SELECT * " myself. But that's neither here nor there.


That wouldn't pass the first set of eyeballs in a code review at our place. Might even become the source of much ribbing and wondering if you were high on something when you wrote it. And that's from the sysadmins.

The coders and DBAs might ask if a rope and a chair and a solid rafter were handy back in the warehouse.

:) :) :)

I'm just going to link this here.

https://www.binpress.com/tutorial/using-php-with-mysql-the-right-way/

It's just the first "decent" example I found of DB abstraction and not writing SQL Injection directly into your PHP script...

There's plenty more examples. Just the tip of this iceberg, really.

The SELECT isn't the only big no-no in your script.

God forbid you have a database error and have high debugging errors turned on in PHP or Apache when that things fails someday when the DB is offline. Instant publish of your DB password without anyone even trying hard.

:)

Think like a bad guy, or they'll do it for you.
 
Oh... Our devs seem to mostly all think PHPStorm is Sierra Hotel. There's always someone who doesn't, but it's popular in our deb group is all I can say.

(I'm a sysadmin. vim works fine for me. Heh.)
 
That wouldn't pass the first set of eyeballs in a code review at our place. Might even become the source of much ribbing and wondering if you were high on something when you wrote it. And that's from the sysadmins.

The coders and DBAs might ask if a rope and a chair and a solid rafter were handy back in the warehouse.

:) :) :)

I'm just going to link this here.

https://www.binpress.com/tutorial/using-php-with-mysql-the-right-way/

It's just the first "decent" example I found of DB abstraction and not writing SQL Injection directly into your PHP script...

There's plenty more examples. Just the tip of this iceberg, really.

The SELECT isn't the only big no-no in your script.

God forbid you have a database error and have high debugging errors turned on in PHP or Apache when that things fails someday when the DB is offline. Instant publish of your DB password without anyone even trying hard.

:)

Think like a bad guy, or they'll do it for you.
I don't claim to be anything more than an amateur... I used to
do pretty good muddling through this stuff, but its been a long time and I seem to be starting from scratch in my understanding... All of it is self-taught from trial and error, and consequently, there are, as you can see, more errors than anything... And self taught automatically means they'll be some unconventional stuff going on... but at my level, as long as it works, I'm a happy camper...:dunno:
 
I don't claim to be anything more than an amateur... I used to

do pretty good muddling through this stuff, but its been a long time and I seem to be starting from scratch in my understanding... All of it is self-taught from trial and error, and consequently, there are, as you can see, more errors than anything... And self taught automatically means they'll be some unconventional stuff going on... but at my level, as long as it works, I'm a happy camper...:dunno:


Understand. We've all been there.

Just keep whatever the bad guys do to the machine contained to your network and keep good backups so you can recover and plug the holes after the exploit! ;)

I've been ranting for over a decade about a need for build standards for software and real engineering tests and certifications for code writing. The code community will never do it on their own.

Never met a single coder yet who declared that everything they have put on the Internet is secure and well written, in fact every one I've ever talked to says they have stuff on the Net that's live right at the time of the discussion that's infinitely crackable.

Software "engineering" as an actual engineering discipline is a total unmitigated disaster. Heck even OS engineering is. Patch Tuesday anyone? LOL.
 
That wouldn't pass the first set of eyeballs in a code review at our place. Might even become the source of much ribbing and wondering if you were high on something when you wrote it. And that's from the sysadmins.

Code review...documentation....good query form...meh. If it was difficult to write it ought to be difficult to understand.

Are there DBAs for MySQL?
 
Code review...documentation....good query form...meh. If it was difficult to write it ought to be difficult to understand.



Are there DBAs for MySQL?


LOL. Ours were forced to do it.

Vast majority of what we run is in a real RDBMS, PostgreSQL.

MySQL is a pain in the ass. The DBAs at least made it tolerable. Legacy cruft from the days when the company was running on a single Windows server for both internal and external users long long ago.

(Yeah, that's not a good idea either. Hey! Let's put our Primary Domain Controller on the Internet serving stuff from both IIS AND Apache -- on the same box -- in PHP and MySQL! I don't think they had a sysadmin back then. If they did here's
hoping he found another line of work...)
 
Back
Top