mysql - Using class for inserting into database (PHP) -


i'm relatively new classes. have table of doctors has id, doc name, address, job , group belong to. have doctor class i've created, , method in class called newdoctor(), inserting new doctor database. i'm not seeing how doing within class advantageous? know classes/objects considered "better", , maybe i'm not implementing or best way, don't know how having method inside class better having function outside of class. please tell me if or if there's better way this!

class doctor {          function newdoctor($doc_info){     $database = new database();     $database -> query('insert doctors (first_name, last_name, address, city, state, zip, group_id, job)      values (:first_name, :last_name, :address, :city, :state, :zip, :group_id, :job)');     $database -> bind(':firstname', $doc_info['firstname']);      $database -> bind(':lastname',  $doc_info['lastname']);      $database -> bind('address',    $doc_info['address']);      $database -> bind(':city',      $doc_info['city']);      $database -> bind(':state',     $doc_info['state']);      $database -> bind(':zip',       $doc_info['zip']);      $database -> bind(':group_id',  $doc_info['group_id']);      $database -> bind(':job',       $doc_info['job']);      $database -> execute();  } } 

i have mysql library , that's database() comes from. works fine.

also, if have have lot of input parameters, "better" pass array or each individual variable? or there better way this?

thanks!

you make proper missed code.

try code:

  function newdoctor($doc_info){     $database = new database();     $database -> query('insert doctors (first_name, last_name, address, city, state, zip, group_id, job)      values (:first_name, :last_name, :address, :city, :state, :zip, :group_id, :job)');     $sth=$this->prepare($database);     $sth -> bind(':firstname', $doc_info['firstname']);      $sth -> bind(':lastname',  $doc_info['lastname']);      $sth -> bind('address',    $doc_info['address']);      $sth -> bind(':city',      $doc_info['city']);      $sth -> bind(':state',     $doc_info['state']);      $sth -> bind(':zip',       $doc_info['zip']);      $sth -> bind(':group_id',  $doc_info['group_id']);      $sth -> bind(':job',       $doc_info['job']);      $sth -> execute();  } } 

i hope work!


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -