How to make PHP variables?

Status
This thread has been locked.

Badger

Software Developer
Supreme
Feedback score
22
Posts
2,366
Reactions
1,561
Resources
2
You clicked this and thought it was the most stupidest question you actually ever saw... No, it's more complex than simple PHP. Here's what I mean. When you use SQL and PHP together, there is a function called mysqli_fetch_object() in which returns the SQL query result rows as objects in which you can then get the columns by their names. Example:
Code:
while ($object = mysqli_fetch_object($result)) {
echo $object->id;
echo $object->username;
echo $object->aUselessColumn;
}
So what I want to know how to do is how to make my own version of that. How do they access the columns like that when they don't have them set until the query?

Basically I need to know the code between in which mysqli_fetch_object() function runs. Thanks!
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Burdened

lets all love lain
Premium
Feedback score
35
Posts
707
Reactions
345
Resources
0
You clicked this and thought it was the most stupidest question you actually ever saw... No, it's more complex than simple PHP. Here's what I mean. When you use SQL and PHP together, there is a function called mysqli_fetch_object() in which returns the SQL query result rows as objects in which you can then get the columns by their names. Example:
Code:
while ($object = mysqli_fetch_object($result)) {
echo $object->id;
echo $object->username;
echo $object->aUselessColumn;
}
So what I want to know how to do is how to make my own version of that. How do they access the columns like that when they don't have them set until the query?

Basically I need to know the code between in which mysqli_fetch_object() function runs. Thanks!

prepared statements will help ;)
PHP:
  $conn = @mysqli_connect('localhost', 'root', 'pass', 'dbname');
   if ($conn === false) {
     return false;
   }

$sql = "SELECT * from table";
$result = $conn->query($sql);

if($result === false) {
echo 'error, something wrong with SQL or conn lul';
} else {
foreach ($row = $result->fetch_assoc()) {
echo '$row["columnname1"]';
echo '$row["columnname2"]';
echo '$row["etc"]';
}
}

try this example,
 

Badger

Software Developer
Supreme
Feedback score
22
Posts
2,366
Reactions
1,561
Resources
2
prepared statements will help ;)
PHP:
  $conn = @mysqli_connect('localhost', 'root', 'pass', 'dbname');
   if ($conn === false) {
     return false;
   }

$sql = "SELECT * from table";
$result = $conn->query($sql);

if($result === false) {
echo 'error, something wrong with SQL or conn lul';
} else {
foreach ($row = $result->fetch_assoc()) {
echo '$row["columnname1"]';
echo '$row["columnname2"]';
echo '$row["etc"]';
}
}

try this example,
You didn't understand the question...
 

Brazy

CEO of Occasionally Returning
Supreme
Feedback score
14
Posts
2,698
Reactions
1,373
Resources
0
prepared statements will help ;)
PHP:
  $conn = @mysqli_connect('localhost', 'root', 'pass', 'dbname');
   if ($conn === false) {
     return false;
   }

$sql = "SELECT * from table";
$result = $conn->query($sql);

if($result === false) {
echo 'error, something wrong with SQL or conn lul';
} else {
foreach ($row = $result->fetch_assoc()) {
echo '$row["columnname1"]';
echo '$row["columnname2"]';
echo '$row["etc"]';
}
}

try this example,
also badger not using some kewl command prompt like font and sizing to help me read it better could help too
 

Badger

Software Developer
Supreme
Feedback score
22
Posts
2,366
Reactions
1,561
Resources
2
also badger not using some kewl command prompt like font and sizing to help me read it better could help too
Already figured it out. I wanted to use the stdClass.
 
Status
This thread has been locked.
Top