r/learnphp • • Aug 15 '24

How can I bind my PDO parameter if I have a decimal(15,9) in my table

3 Upvotes

I'm following a tutorial and i need to bind a parameter to my sql statement. The tutorial says to bind the parameter using this statement :

"$query->bind_parameter(':area', $area, PDO::PARAM_STR)".

But I adapted the tutorial to my needs and the problem that I face is that the data type in my sql table is decimal(15,9). I did some searching and, to my knowledge, PDO only has PARAM_INT and PARAM_STR. So how can i fix this bind a decimal parameter in PDO?


r/learnphp • • Apr 28 '23

Which IDE do you prefer for PHP development and why?

3 Upvotes

I see this question was last asked years ago so maybe something has changed since then as I'm debating using VS Code or PHP-Storm perhaps but wanted to see if I'm missing any other option or preference and why too.


r/learnphp • • Sep 20 '22

What Is the Fastest Way To Learn Programming

Thumbnail
jesuitasdeloyola.org
3 Upvotes

r/learnphp • • Aug 23 '22

How to get data from the database in Symfony?

Thumbnail
devhubby.com
3 Upvotes

r/learnphp • • Mar 09 '22

Is PHP the best solution for this?

3 Upvotes

I'm looking to build from the ground up a website that would be similar to a massively simpler version of ebay. It would need functionality like user account creation, profiles, uploading data etc.

So lots of interacting with databases. Is PHP still the best solution for this? Will probably use Javascript for validation etc but for fetching/uploading data, session control etc is PHP the answer or is there something newer and sexier out there?

Thanks


r/learnphp • • Nov 14 '21

Easiest way to take a bunch of MySQL rows returned from a SELECT and then do a batch CREATE request to a MSSQL db?

3 Upvotes

I would like to know what function to use for the fetch and what function to use for the batch CREATE and which library. Thanks.


r/learnphp • • Aug 20 '21

Performance issue reported

3 Upvotes

top - 16:39:36 up 1106 days, 23:34, 1 user, load average: 3.40, 5.27, 8.57 Tasks: 328 total, 5 running, 323 sleeping, 0 stopped, 0 zombie Cpu(s): 42.7%us, 3.9%sy, 0.0%ni, 44.1%id, 12.5%wa, 0.0%hi, 0.5%si, 0.3%st Mem: 32877280k total, 29958444k used, 2918836k free, 5932496k buffers Swap: 0k total, 0k used, 0k free, 1895848k cached

What should I do?

Idle time is "high" and IO wait is low:

Your slowness isn't due to CPU or IO problems, so it's likely an application-specific issue. It's also possible that the slowness is being caused by another server in your cluster, or by an external service you rely on.

I am thinking it's the DB, but can I do anything to make it faster instantly? Any config change or do I just need to optimize the SQL queries. Is there any hardware change I should make, what other changes can I make to make it faster.


r/learnphp • • Jul 26 '21

In a 2 column layout - display results in 2nd column on same page.

3 Upvotes

I have a 2-column layout with menu on the left and video on the right. The menu is populated as a list via mysql. When choosing a video from the menu, I would like the result to be shown in the right column without leaving the single page. Suggestions appreciated.

My simplified code looks like this:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
</head>
<body>

<h2>Videos</h2>
<?php include 'db_conn.php'; $sql = 'SELECT * FROM videos ORDER BY id DESC'; $res = mysqli_query($conn, $sql) ?>
<div class="row">
  <div class="column left" style="background-color:#aaa;">
    <h2>Menu</h2>
    <?php if (mysqli_num_rows($res) > 0) { while ($video = mysqli_fetch_assoc($res)) { ?>
    <ul>
      <li><a href="#?video_id=<?php echo $video['id']; ?>"><?= $video['title'] ?></a></li> 
      </ul>
      <?php } } else { echo 'Empty'; } ?> 
  </div>
  
  <div class="column right" style="background-color:#bbb;">
    <h2>Video</h2>
    <?php include 'db_conn.php'; $sql = 'SELECT * FROM videos ORDER BY id DESC'; $res = mysqli_query($conn, $sql) ?> 
    <video width="400" controls>
  <source src=""uploads/<?= $video['video_url'] ?>"" type="video/mp4"> 
  Your browser does not support HTML5 video.
</video>

  </div>
</div>

</body>
</html>

r/learnphp • • Jun 17 '21

What are the best deployment tech for php?

3 Upvotes

I think we used puppet, but I am looking for something modern and that won't get deprecated like puppet, which seems to be deprecated somehow.


r/learnphp • • Jun 10 '21

How do you find out the username and password that are being used?

3 Upvotes

<body id="error-page">

<div class="wp-die-message"><h1>Error establishing a database connection</h1>

<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can\&#8217;t contact the database server at <code>mariadb</code>. This could mean your host\&#8217;s database server is down.</p>

<ul>

<li>Are you sure you have the correct username and password?</li>

<li>Are you sure you have typed the correct hostname?</li>

<li>Are you sure the database server is running?</li>

I am trying to deploy something to staging and I am using puppet, but every time I try to deploy I get this at the end. Is there a way to find out what's the username and password that are being used, and what hostname is being used? I tried to connect to the db using the information I had from puppet and I could easily connect to the database, so I have no idea what's causing this.


r/learnphp • • Jun 10 '21

How do you direct request to server when cookie is not set in varnish?

3 Upvotes

How do you direct request to server when cookie is not set in varnish? I don't want to return the cache to the user when the cookie "language" is not set, and instead I want to send the request to apache, how do I do this?


r/learnphp • • May 29 '21

How do you deploy an application to production with docker?

3 Upvotes

I have a yml file and everything, and I can run the yml file locally. Do you just need to do docker-compose up if you have the yml file? Where in the yml file can you get the url the website will be accessible from?


r/learnphp • • May 21 '21

Search function not working sql

3 Upvotes

I want to make a search in php using sql but i get a Undefined error. i tried using emty and isset but it doesnt work.

how can i first check if i can get the value and then proceed. i even tried first checking if get exist but that did also not work

<?php

// Laad alle database gerelateerde functions in.

include("Uitleg1/functions/db_functions.php");

// Start een connectie met de database

startConnection();

// Maak een variabele met de SQL query

$query = "SELECT * FROM tblRiddles";

// Controleer of $_GET["txtRiddleAnswer"] NIET leeg is.

// Taak 4: Programmeer hieronder je code

if (isset($_GET["txtCreator"])) {

$query = "SELECT * FROM tblRiddles ";

}

if (isset($_GET["txtCreator"])) {

$query = "SELECT * FROM tblRiddles WHERE RiddleText LIKE '%" . $_GET["txtRiddleText"] . "%'";

}

elseif (empty($_GET['txtRiddleText']) == false and empty($_GET["txtCreator"]) == false) {

$query = "SELECT * FROM tblRiddles WHERE RiddleText LIKE '%". $_GET["txtRiddleText"] . "%' AND Creator= '". $_GET['txtCreator']. "'";

}

elseif (empty($_GET['txtCreator']) == false and empty($_GET["txtRiddleText"]) == true)

{

$query = "SELECT * FROM tblRiddles WHERE Creator='" . $_GET['txtCreator'] . "'";

}

// Voer de geschreven SQL query uit op de database

// Vang daarna het resultaat in de variabele $result

$result = executeQuery($query);

echo $query;

echo "<table>";

echo "<tr>";

echo "<th>ID:</th>";

echo "<th>Raadsel:</th>";

echo "<th>Oplossing:</th>";

echo "<th>Bedenker:</th>";

echo "<th>Datum:</th>";

echo "</tr>";


r/learnphp • • May 17 '21

Can we use other APIs instead of the Google Business API to fetch the avg review score and the number of reviews?

3 Upvotes

https://developers.google.com/places/web-service/details

Can we use other APIs instead of the Google Business API to fetch the avg review score and the number of reviews? Is there a downside? I don't want to use the Google Business API, because we have 12 accounts and each of them are tied to an employee cellphone number for some odd reason.


r/learnphp • • Apr 18 '21

HTML form input field naming convention for submission to PHP backend?

3 Upvotes

Hi,

I'm looking for any nomenclature or naming convention standard for naming html form input fields when the data in the fields is to be submitted to a PHP backend. Hopefully some guidance that integrates into browser auto-complete functionality.

So to illustrate, if i am capturing visitors first name in an html form that will send data to a PHP backend, should i use naming convention of -

Name: <input type="text" name="**fname**" >

Or

Name: <input type="text" name="**firstName**" >

Or

Name: <input type="text" name="**given-name**">

Is there some kind of standardization existing that i should adhere to?


r/learnphp • • Apr 01 '21

Is there a way to check whether that we're on the same month as date x?

3 Upvotes

Let's say I choose February 21, then I want a function to return true if today's date is March 1st or March 30th and so on so forth. So basically any date on February should return true if we're on March. Not sure what's the best way to do this.


r/learnphp • • Feb 19 '21

I cannot webcrawl using curl, what can be done about it?

3 Upvotes

https://codepen.io/codepen_user_123/pen/KKNvWwQ

I tried to webcrawl a google page, but then I noticed the html I get using curl is completely different from the html I end up getting. My script works when I manually paste the html of the website, but doesn't work when the html is obtained through curl.


r/learnphp • • Jan 30 '21

Where do I start? I have always wanted to learn how to develop software but new know where to start from. I tried different means but still have difficulty understanding the principles. I get lost in trying to understand everything and at the end of the day achieve nothing. Where do I start?

3 Upvotes

r/learnphp • • Jan 22 '21

Where to start with Laracasts

3 Upvotes

I've just finished learning the basics of procedural PHP for an upcoming project. After lots of advice and reading old threads here I've decided to go with the Laravel framework as it seems the best fit, and it seems that Laracasts is unanimously considered the best learning resource for it, but where the hell do I start? There's 60 Laravel courses on that page, no way to sort by beginner topics and no way to know where to get started with the latest version of Laravel, it seems like more of an information/course dump than anything. The only thing I've seen is the Laracasts from Scratch course, but that's now two years old - is that a good idea?

As a bonus, should I learn OOP separately - I already have my eye on a cheap Udemy course with the same instructor I used to learn PHP - or will the Laracasts Laravel track take the time out to teach that too?


r/learnphp • • Jan 02 '21

What are some good GitHub projects that are easy to dockerize?

3 Upvotes

Trying to learn to dockerize simple LAMP applications. I don't mind if they're slightly difficult.


r/learnphp • • Dec 29 '20

Slim: Lingering questions after 1 1/2 weeks of tutorial-ing....

3 Upvotes

Been delving deep into the Slim framework for the better part of a week and a half or so, finally starting to feel like I can make something happen. Having focused so much on JS and it’s relevant frameworks wasn’t expecting it to be so.. involved? IDK it’s just been difficult cuz every tutorial I found went through some really complex setup code just to get to the point of creating routes, and every one of them had vastly different approaches, while all I’m looking for is a simple API framework to accept and return JSON.

Anyway, this tutorial seemed to finally ‘click’ with me and I intend to follow its pattern more or less to a T. But I still have a question or two:

Firstly, I just wanna make sure I understand what’s happening with how this guy structured his route dependencies. Review the github repo for further clarification but here's one route in a nutshell:

  • /users/{id} invokes UserReadAction

  • UserReadAction depends on UserReader service

  • UserReader service depends on UserReaderRepository

  • UserReaderRepository depends on a singleton PDO connection to fetch data and create a UserReaderData object, which then gets returned back up the dependency chain and into the response served by the UserReadAction.

Not hard to comprehend, but that's not my issue. What strikes me is that none of those classes are registered in the container (except for the PDO connection), yet, Slim seems to be magically performing dependency injection anyway. To my understanding, it's the container which is responsible for the dependency injection, so... What am I missing here? Does Slim perform dependency injection inherently? Or is it simply that Slim is smart enough to utilize the container's magical autowiring capabilities on its own? Sorry, I know it's a poorly formed question but this is truly baffling and mind-blowing to me and I want to be sure I understand what's going on...

This also begs the question: when/why is it appropriate to explicitly register dependencies in the container? For instance, my current project will use token-based authentication and I'm wondering how to implement my Tokenizer class that will have the generate and verify methods, as it will be shared amongst virtually every route. Do I register it in the container? Or... I mean if Slim will inject it where necessary then why don't I just include it in the constructor in the relevant Service and Middleware classes where it will be used? The dependency container almost seems trivial if the latter is possible....


r/learnphp • • Dec 20 '20

ISO Easy(-ish) PHP REST framework

3 Upvotes

I'm just starting out on a project where I intend to use Svelte.js for the frontend and PHP for the backend. To put it another way: I'm basically thinking that Svelte will be my 'VC' and the PHP will simply deal with the 'M'. As such, my API only needs to accept/return JSON, that's it.

I've tried an implementation like this in the past, but my API end up being such a steaming pile of s*** that even I can't debug it at this point -- the definition of spaghetti code, I can admit.

So I'm looking into PHP frameworks for this project. I discovered Slim just the other day and.. holy boiler plate. I'm on my fourth tutorial series and I still just... don't get it. I mean, for real, the 5th video in that series is still just setting up Slim and it's an hour long?!

Is this just how PHP frameworks are? Or is there another framework you fine folks would suggest I should look into that suits my needs more or less out of the box?


r/learnphp • • Aug 23 '20

API Throttle Using Laravel 7 - Phpflow.com

Thumbnail
phpflow.com
3 Upvotes

r/learnphp • • Aug 07 '20

Resource Why I enjoy coding Kata's

3 Upvotes

I've written a blog post on Why I enjoy coding Kata's, I hope it will be beneficial for fellow PHP coders to learn new skills, not only in coding but also PHP tooling which is available.