Jump to content

Mad programmer

Members
  • Posts

    26
  • Joined

  • Last visited

  • Days Won

    1

Mad programmer last won the day on May 11 2013

Mad programmer had the most liked content!

Profile Information

  • Gender
    Not Telling

Mad programmer's Achievements

Newbie

Newbie (1/5)

1

Reputation

  1. For the loop I'd recommend to use a nested foreach.(on the array you've used in your print_r) The first foreach kan be used like: Foreach($array as $key => $value) { ... } Where $key is example.com and value are its children. So then do another foreach inside this one with the $value as an array. That should work!
  2. You may wish to add a print_r($myArray) between the html pre tags. <pre> </pre>. That will give the desired result!
  3. Well I do use symfony's components, I am looking into the full stack framework but currently I am not using it for a project or anything. Maybe you can write a service that does the job? It may be a little more work right now but It will safe time if you need this particular function more then once in your application.
  4. True, But how about getting the form validators output first? And retrieve the values only and store those along with the request parameters in the session? That way you don't have to run the validators again, and you have the data
  5. Why not just write the form values from the request object to the session? And in your view you bind those values to the form again? I cannot think of any way why that should not work Then you don't have write the complete form object into a session.
  6. Hi Jessica, I am not familiar with behat, but maybe it uses output buffering internally? So I'd try to catch the output buffer and end it, after that you echo your content and then reenable the output buffer with that content?
  7. Hello, If you include the script from another script you can set a variable like: $allowSend = true; And then simply check if that variable is not null and is true, else exit. If it is a standalone script you may use sessions for this.
  8. Hello, Why not just append to the string? $string .= '.html';?
  9. Woa woa hold there you DO know how to use a variable in a string right? Take my modified example from above and BEFORE that do this; $id = $_SESSION['userid']; bindParam is not working with query but only with prepared statements.. the fetch function is only taking pdo arguments such as PDO::FETCH_ASSOC. My modified example is all you need, you're combining prepared pdo wirh normal query statements and that wont work.
  10. That is correct, however PDO does not always require that much lines of code. The prepare functions are for safety purposes. It would be good practice to put these to use. But in your case you typecast to an int by using intval which may also be passed directly to a sql query. You can do this with PDO like so: (Example taken from php.net/pdo and modified a bit) <?PHP $users = $pdo->query("SELECT * FROM users WHERE id = {$id}")->fetch(); ?> Sorry for not using codetags but I am on my cell phone right now.
  11. If you by different syntax mean the way of constructing a query in PDO then no. Except for binding the parameters. This is because pdo sends the query to the mysql server and afterwards your binded parameters. As of php 5.5 the mysql_* functions will be removed(I think) and you will need to use pdo or the mysqli functions for your scripts. MySQL itself cannot be shutdown since it is just a database software package, the interfaces for php are a different story
  12. Well MySQL is the language for the database itself while PDO is an abstraction layer for the database. You can still use variables in a string like you did right there, however the bindParam also makes sure your data is safe and it protects against sql injections.
  13. Have you tried to run my supplied code example? You will see that $user is an array. The array contains your database columns so you echo them like this: echo $user['username'];
  14. True, but I was talking about execute and not exec This is what the docs say: You do NOT want the affected rows but you want to retrieve the rows themself which is done like this: <?php $id = 441; $query = $db->prepare('SELECT * FROM users WHERE id = :id'); // You first PREPARE the query $query->bindParam(':id', $id); // You bind the required parameters for your query $query->execute(); // This sends the query to the SQL server $user = $query->fetch(PDO::FETCH_ASSOC); // Specify the PDO::FETCH_ASSOC to fetch the data as an associative array (not required) echo '<pre>'; // I always PRE before I print an array which makes it more readable in the browser print_r($user); // This contains your fetched row from the sql server ?> Please compare the above piece of code to what you have written and note the differences.
  15. You forgot to call $query-execute(); which executes the prepared statement. After that you may retrieve the data so: $query->fetch(); which returns the data as an array;
×
×
  • 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.